package demo1.web.servlet.userBuyapi;

import demo1.dao.Mapper.userBuyMapper;
import demo1.pojo.userBuy;
import demo1.dao.sql.userBuysql;
import demo1.service.userBuyService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/userBuyModifyPwd")
public class userBuyModifyPwd extends HttpServlet {//修改用户的密码
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String userPwd = req.getParameter("userPwd");//获取密码
        resp.setContentType("text/html;charset = utf-8");

        //获取session对象
        HttpSession session = req.getSession();
        Object userObject = session.getAttribute("users");
        userBuy users = (userBuy) userObject;

        try {
            userBuyService modify = new userBuyService();
            modify.userBuyModifyPwd(userPwd, users.getGouwuid());
            resp.sendRedirect("/logindemo2/showUserBuy.jsp");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
